package com.ruoyi.controller;

import java.text.SimpleDateFormat;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.domain.CwDealPerDayDetail;
import com.ruoyi.domainVo.TCwDealPerDayVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.domain.TCwDealPerDay;
import com.ruoyi.service.ITCwDealPerDayService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 营业报表Controller
 * 
 * @author ruoyi
 * @date 2023-02-24
 */
@RestController
@RequestMapping("/property")
public class TCwDealPerDayController extends BaseController
{
    @Autowired
    private ITCwDealPerDayService tCwDealPerDayService;

    /**
     * 查询营业报表列表
     */
    @RequiresPermissions("property:property:list")
    @GetMapping("/list")
    public TableDataInfo list(TCwDealPerDayVo tCwDealPerDay)
    {
        if(tCwDealPerDay.getOperationType()!=null){
            tCwDealPerDay.setOperationType(tCwDealPerDay.getOperationType());
        }else{
            tCwDealPerDay.setOperationType(1L);
        }
        startPage();
        List<TCwDealPerDay> list = tCwDealPerDayService.selectTCwDealPerDayList(tCwDealPerDay);
        return getDataTable(list);
    }



    /**
     * 导出营业报表列表
     */
    @RequiresPermissions("property:property:export")
    @Log(title = "营业报表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TCwDealPerDayVo tCwDealPerDay)
    {
        List<TCwDealPerDay> list = tCwDealPerDayService.selectTCwDealPerDayList(tCwDealPerDay);
        ExcelUtil<TCwDealPerDay> util = new ExcelUtil<TCwDealPerDay>(TCwDealPerDay.class);
        util.exportExcel(response, list, "营业报表数据");
    }

    /**
     * 获取营业报表详细信息
     */
    @RequiresPermissions("property:property:query")
    @GetMapping(value = "/detail")
    public AjaxResult getInfo(TCwDealPerDayVo tCwDealPerDay)
    {
        if(tCwDealPerDay.getStartDate()!=null){
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            String format = simpleDateFormat.format(tCwDealPerDay.getStartDate());
            tCwDealPerDay.setDate(format);
        }
        List<CwDealPerDayDetail> tCwDealPerDays = tCwDealPerDayService.selectTCwDealPerDayById(tCwDealPerDay);
        System.out.println(tCwDealPerDays);
        return success(tCwDealPerDays);
    }


    /**
     * 修改营业报表
     */
    @RequiresPermissions("property:property:edit")
    @Log(title = "营业报表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TCwDealPerDay tCwDealPerDay)
    {
        return toAjax(tCwDealPerDayService.updateTCwDealPerDay(tCwDealPerDay));
    }

}
